package com.springcloud.alibabanacosconfig.mq.component;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import java.util.HashMap;
import java.util.Map;

/**
 * @version V1.0
 * @Author 宋聚智
 * @Date 2019/10/23 15:37
 * @description
 * @Modify By：
 * @ModifyTime： 2019/10/23
 * @Modify marker：
 **/
@Configuration
public class OrderTradeConfig {
    @Autowired
    private Environment env;
    //延迟队列配置
    @Bean(name="orderTradeDelayQueue")
    public Queue orderTradeDelayQueue(){
        Map<String,Object> params = new HashMap<>();
        params.put("x-dead-letter-exchange",env.getProperty("order.trade.exchange.name"));
        params.put("x-dead-letter-routing-key","all");
        return new Queue(env.getProperty("order.trade.delay.queue.name"),true,false,false,params);
    }
    @Bean
    public DirectExchange orderTradeDelayExchange(){
        return new DirectExchange(env.getProperty("order.trade.delay.exchange.name"));
    }

    @Bean
    public Binding orderTradeDelayBinding(){
        return BindingBuilder.bind(orderTradeDelayQueue()).to(orderTradeDelayExchange()).with("");
    }

    //指标消费队列配置
    @Bean
    public Queue orderTradeQueue(){
        return new Queue(env.getProperty("order.trade.queue.name"));
    }

    @Bean
    public TopicExchange orderTradeTopicExchange(){
        return new TopicExchange(env.getProperty("order.trade.exchange.name"));
    }

    @Bean
    public Binding registerBinding(){
        return BindingBuilder.bind(orderTradeQueue()).to(orderTradeTopicExchange()).with("all");
    }
}
